package com.ylx.web.s;

import com.alibaba.fastjson.JSON;
import com.ylx.pojo.Goods;
import com.ylx.service.GoodsService;
import com.ylx.service.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {
            private GoodsService goodsService=new GoodsServiceImpl();
    protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List<Goods> goods = goodsService.selectAll();

       String jsonString=JSON.toJSONString(goods);

        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
        System.out.println(jsonString);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doGet(request, response);

    }
}
